/*
 * rwlocuca.c
 *
 *  Created on: 31/07/2012
 *      Author: utnso
 */

#include "rwlocuca.h"

static rwlocuca_t rwlocuca = RWLOCUCA_INITIALIZER;

void rwlocuca_push(id_node_t** queue, uint32_t id){
	id_node_t* id_aux = malloc(sizeof(id_node_t));
	id_aux->id = id;
	/*if(*list_head == NULL){
		*list_head = *list_tail = id_aux;
	}else{
		*list_tail = (*list_tail)->sig = id_aux;
	}*/
	if(*queue == NULL){
		id_aux->sig = *queue = id_aux;
	}else{
		id_aux->sig = (*queue)->sig;
		(*queue)->sig = id_aux;
	}
}

uint32_t rwlocuca_pull(id_node_t** queue){
	id_node_t* id_aux = *list_head;
	*list_head = (*list_head)->sig;
	if(*list_head == NULL){
		*list_tail = NULL;
	}
	uint32_t id = id_aux->id;
	free(id_aux);
	return id;
}

void rwlocuca_wrlock(uint32_t* id){
	pthread_mutex_lock(rwlocuca.list_mutex);
	pthread_mutex_unlock(rwlocuca.list_mutex);
}

void rwlocuca_rdlock(uint32_t* id){
	pthread_mutex_lock(rwlocuca.list_mutex);
	pthread_mutex_unlock(rwlocuca.list_mutex);
}
